package org.bhf.service;

/**
 * Copyright (c) 2007, Blue Hole Software. All rights reserved.
 * Code licensed under the Apache 2.0 License:
 * http://www.apache.org/licenses/
 */

import org.bhf.util.AnnotationAccess;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Configuration for a <code>ServiceGroupInfo</code>.
 */
@Documented
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.TYPE)
public @interface ServiceGroupInfo
{
    /**
     * Utility accessors for <code>ServiceGroupInfo</code>
     * @exclude
     */
    public static final class Util
    {
        static final Class<ServiceGroupInfo> clazz = ServiceGroupInfo.class;

        /**
         * Obtain the <code>ServiceGroupInfo</code> annotation for the specified <code>Class</code>.
         * @param serviceClass the target <code>Class</code>.
         * @return the <code>ServiceName</code> annotation for the specified <code>Class</code>
         *      if it exists; otherwise <code>null</code>.
         */
        public static ServiceGroupInfo get( final Class<? extends ServiceGroup> serviceClass )
        {
            return AnnotationAccess.getAnnotation( serviceClass, clazz );
        }

        /**
         * Returns the <code>ServiceName</code>s associated with this <code>ServiceGroupInfo</code>. May be <code>null</code>.
         * @param moduleClass The <code>Class</code> of the <code>ServiceGroupInfo</code>.
         * @return the <code>ServiceName</code>s associated with this <code>ServiceGroupInfo</code>. May be <code>null</code>.
         */
        public static Class<?>[]    services( final Class<? extends ServiceGroup> moduleClass )
        {
            final ServiceGroupInfo moduleInfo = Util.get( moduleClass );
            return moduleInfo != null ? moduleInfo.services() : null;
        }

        /**
         * Return the name of this <code>ServiceGroupInfo</code>
         * @param moduleClass The <code>Class</code> of the <code>ServiceGroupInfo</code>.
         * @return the name of this <code>ServiceGroupInfo</code>
         */
        public static String                        getName( final Class<? extends ServiceGroup> moduleClass )
        {
            final ServiceGroupInfo moduleInfo = Util.get( moduleClass );
            return moduleInfo != null ? moduleInfo.name() : null;
        }
    }

    /**
     * Returns the <code>ServiceName</code> <code>Class</code>es associated with this <code>ServiceGroupInfo</code>.
     * @return the <code>ServiceName</code> <code>Class</code>es associated with this <code>ServiceGroupInfo</code>.
     */
    Class<?>[]  services();

    /**
     * Returns the name of this <code>ServiceGroupInfo</code>.
     * @return the name of this <code>ServiceGroupInfo</code>.
     */
    String      name();
}
